package org.evasoft.museum.cataloger.json.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.evasoft.museum.cataloger.dto.CatalogDTO;
import org.evasoft.museum.cataloger.dto.FieldDTO;

import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("json-default")
@Namespace("/data/catalog")
public class CatalogListAction extends ActionSupport{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -732158582629991203L;
	
	private List<CatalogDTO> catalogs;
	
	public List<CatalogDTO> getCatalogs() {
		return catalogs;
	}

	public void setCatalogs(List<CatalogDTO> catalogs) {
		this.catalogs = catalogs;
	}

	@Action(value="getCatalogList", results= {
			@Result(name="success",type="json")
	})
	public String execute(){
		catalogs = new ArrayList<CatalogDTO>();
		for(long i=1;i<=10;i++){
			CatalogDTO catalog = createCatalog(i);
			catalogs.add(catalog);
		}		
		return SUCCESS;		
	}
	
	public CatalogDTO createCatalog(Long id){
		CatalogDTO catalog = new CatalogDTO();	
		catalog.setId(id);
		catalog.setName("Obras");
		catalog.setFields(createFields());
		return catalog;
	}
	
	public List<FieldDTO> createFields(){
		List<FieldDTO> fields = new ArrayList<FieldDTO>();
		for(long i=1;i<=10;i++){
			FieldDTO field = new FieldDTO();
			field.setType("string");
			field.setName("Titulo de la obra");
			field.setLabel("Titulo");
			field.setData_validation("text");
			field.setId(i);
			fields.add(field);
		}
		return fields;
	}


}
